package fun.ticsmyc.provider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import fun.ticsmyc.common.pojo.Book;
import fun.ticsmyc.common.service.BookService;
import fun.ticsmyc.provider.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Ticsmyc
 * @date 2020-03-21 15:14
 */
@Service(version = "1.0.0")
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    /**
     * 增
     *
     * @param name
     * @return
     */
    @Override
    public boolean add(String name) {
        Book temp = new Book();
        temp.setName(name);
        int res = bookMapper.insert(temp);
        if(res ==1){
            return  true;
        }else{
            return false;
        }
    }

    /**
     * 删
     *
     * @param id
     * @return
     */
    @Override
    public boolean delete(int id) {
        Book temp = new Book();
        temp.setId(id);
        int res = bookMapper.delete(temp);
        System.out.println("delete: "+res);
        return true;
    }

    /**
     * 根据id查
     *
     * @param id
     * @return
     */
    @Override
    public Book queryById(int id) {
        Book temp =new Book();
        temp.setId(id);
        System.out.println(id);
        return bookMapper.selectOne(temp);
    }

    /**
     * 根据name查
     *
     * @param name
     * @return
     */
    @Override
    public List<Book> queryByName(String name) {
        Book temp =new Book();
        temp.setName(name);
        return bookMapper.select(temp);
    }
}
